package org.dandsoft.blackbox.labs.snn;

import java.io.IOException;
import java.io.StringWriter;
import java.io.File;
import java.io.FileWriter;

/**
 * User: dvilyuzhanin
 * Date: 25.01.2009 17:10:06
 * Generate the neuron structure as steps.
 */
@Deprecated
public class StepsGenerator {

    private int connectivityLevel;
    private int startNeuronsCount;
    private int stepLenght;
    private double stepHeight;
    private int totalSteps;
    private int upStepsCount;
    private int downStepsCount;


    public void generate(NeuronStructureWriter writer, NeuronLayerGenerator layerGenerator) throws IOException {
        LoadingModel model = new LoadingModel();
        model.setConnectivityLevel(connectivityLevel);
        model.setFrontSize(stepHeight);
        model.setSourceNeuronsCount(startNeuronsCount);

        for (int step = 0; step < totalSteps; step++) {

            for (int i = 0; i < stepLenght; i++) {
                layerGenerator.generate(model);
                writer.write(layerGenerator);
                writer.flush();

                model.next();
                model.setFrontSize(1);
            }
            model.next();
            model.setFrontSize(stepHeight);

        }


        model.setFrontSize(stepHeight);
        layerGenerator.generate(model);
        writer.write(layerGenerator);
        writer.flush();
        /*for (int step = 0; step < totalSteps; step++) {
            if (step > 0) {
                model.setFrontSize(stepHeight);
            }
            for (int i = 0; i < stepLenght; i++) {
                model.next();
                layerGenerator.generate(model);
                writer.write(layerGenerator);
                writer.flush();
                model.setFrontSize(1);
            }
        }*/
    }

    public static void main(String[] args) throws Exception {


        FileWriter file = new FileWriter("e:/test.nstr", false);
        NeuronStructureWriter writer = new NeuronStructureWriter(file);
        try {
            NeuronLayerGenerator layerGenerator = new NeuronLayerGenerator();
            StepsGenerator generator = new StepsGenerator();

            generator.setTotalSteps(100);
            generator.setStepLenght(2);
            generator.setStepHeight(1.5);
            generator.setConnectivityLevel(2);
            generator.setStartNeuronsCount(1);

            generator.generate(writer, layerGenerator);
        } finally {
            file.close();
        }


    }

    public int getStepLenght() {
        return stepLenght;
    }

    public void setStepLenght(int stepLenght) {
        this.stepLenght = stepLenght;
    }

    public double getStepHeight() {
        return stepHeight;
    }

    public void setStepHeight(double stepHeight) {
        this.stepHeight = stepHeight;
    }

    public int getTotalSteps() {
        return totalSteps;
    }

    public void setTotalSteps(int totalSteps) {
        this.totalSteps = totalSteps;
    }

    public int getUpStepsCount() {
        return upStepsCount;
    }

    public void setUpStepsCount(int upStepsCount) {
        this.upStepsCount = upStepsCount;
    }

    public int getDownStepsCount() {
        return downStepsCount;
    }

    public void setDownStepsCount(int downStepsCount) {
        this.downStepsCount = downStepsCount;
    }

    public int getConnectivityLevel() {
        return connectivityLevel;
    }

    public void setConnectivityLevel(int connectivityLevel) {
        this.connectivityLevel = connectivityLevel;
    }

    public int getStartNeuronsCount() {
        return startNeuronsCount;
    }

    public void setStartNeuronsCount(int startNeuronsCount) {
        this.startNeuronsCount = startNeuronsCount;
    }
}
